<?php

defined('IN_IA') or exit('Access Denied');

global $_W,$_GPC;


if(empty($_GPC['op'])){

	$operation = 'list';

}else{

	$operation = $_GPC['op'];

}

if($operation == 'list'){

	$pindex    = max(1, intval($_GPC['page']));

	$psize     = 20;

	$array = array(':uniacid'=>$_W['uniacid']);
	
	$wheres = " AND uniacid=:uniacid ";

	if(!empty($_GPC['type'])){

		$wheres.=" and type=:type  ";

		$array[':type'] = $_GPC['type'];
		
	}

	$sql = "SELECT * FROM ".tablename("xuan_hb_huan")." WHERE  1 {$wheres}";

	$sql .= " limit " . ($pindex - 1) * $psize . ',' . $psize;

	$list = pdo_fetchall($sql,$array);

	$total           = pdo_fetchcolumn("select count(*) from" . tablename('xuan_hb_huan')." WHERE 1 {$wheres} ",$array);
	
	$pager           = pagination($total, $pindex, $psize);
}else if($operation=='add'){

	if($_GPC['post']==1){

		$_GPC['da']['logo'] = $_GPC['logo'];

		$_GPC['da']['createtime'] = time();

		$_GPC['da']['uniacid'] = $_W["uniacid"];

		pdo_insert("xuan_hb_huan",$_GPC['da']);

		message("添加成功",$this->createWebUrl('huan'));
	}

}else if($operation=='update'){

	$item = pdo_fetch("SELECT * FROM ".tablename("xuan_hb_huan")." WHERE id=:id ",array(":id"=>$_GPC['id']));
	$item['content']=json_decode($item['content'],1);
	if($_GPC['post']==1){

		$_GPC['da']['logo'] = $_GPC['logo'];

		$_GPC['da']['createtime'] = time();

		$_GPC['da']['uniacid'] = $_W["uniacid"];

		pdo_update("xuan_hb_huan",$_GPC['da'],array("id"=>$_GPC['id']));

		message("更新成功",$this->createWebUrl('huan'));
	}

}else if($operation=='delete'){

	pdo_delete('xuan_hb_huan',array("id"=>intval($_GPC["id"])));

	message("删除成功",$this->createWebUrl('huan'));
}

include $this->template('web/huan');

?>